package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DocCategory;
import com.ruoyi.system.service.IDocCategoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 文档分类Controller
 * 
 * @author ruoyi
 * @date 2025-04-25
 */
@Controller
@RequestMapping("/system/category")
public class DocCategoryController extends BaseController
{
    private String prefix = "system/category";

    @Autowired
    private IDocCategoryService docCategoryService;

    @RequiresPermissions("system:category:view")
    @GetMapping()
    public String category()
    {
        return prefix + "/category";
    }

    /**
     * 查询文档分类列表
     */
    @RequiresPermissions("system:category:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DocCategory docCategory)
    {
        startPage();
        List<DocCategory> list = docCategoryService.selectDocCategoryList(docCategory);
        return getDataTable(list);
    }

    /**
     * 导出文档分类列表
     */
    @RequiresPermissions("system:category:export")
    @Log(title = "文档分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DocCategory docCategory)
    {
        List<DocCategory> list = docCategoryService.selectDocCategoryList(docCategory);
        ExcelUtil<DocCategory> util = new ExcelUtil<DocCategory>(DocCategory.class);
        return util.exportExcel(list, "文档分类数据");
    }

    /**
     * 新增文档分类
     */
    @RequiresPermissions("system:category:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存文档分类
     */
    @RequiresPermissions("system:category:add")
    @Log(title = "文档分类", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DocCategory docCategory)
    {
        return toAjax(docCategoryService.insertDocCategory(docCategory));
    }

    /**
     * 修改文档分类
     */
    @RequiresPermissions("system:category:edit")
    @GetMapping("/edit/{categoryId}")
    public String edit(@PathVariable("categoryId") Long categoryId, ModelMap mmap)
    {
        DocCategory docCategory = docCategoryService.selectDocCategoryByCategoryId(categoryId);
        mmap.put("docCategory", docCategory);
        return prefix + "/edit";
    }

    /**
     * 修改保存文档分类
     */
    @RequiresPermissions("system:category:edit")
    @Log(title = "文档分类", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DocCategory docCategory)
    {
        return toAjax(docCategoryService.updateDocCategory(docCategory));
    }

    /**
     * 删除文档分类
     */
    @RequiresPermissions("system:category:remove")
    @Log(title = "文档分类", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(docCategoryService.deleteDocCategoryByCategoryIds(ids));
    }
}
